home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
fish
/
701-725
/
704
/
sunclock
/
src.lha
/
Timer.c
< prev
Wrap
C/C++ Source or Header
|
1992-01-05
|
2KB
|
74 lines
/*-------------------------------------------------------------------------
SunClock
Amiga version by Mark Waggoner,
waggoner@ichips.intel.com or wagnell@PDaXcess.techbook.com
December 1991
Timer.c
Functions for dealing with the timer device
-------------------------------------------------------------------------*/
#include <functions.h>
#include <devices/timer.h>
extern struct MsgPort *Timer_Port;
extern struct timerequest Time_Request;
extern ULONG TimerMask;
#define IOR (struct IORequest *)
/*************** Close the message port and the timer device **************/
void
CloseTimer(void) {
if (Time_Request.tr_node.io_Message.mn_ReplyPort) {
AbortIO(IOR &Time_Request);
WaitIO(IOR &Time_Request);
CloseDevice(IOR &Time_Request);
Time_Request.tr_node.io_Message.mn_ReplyPort = NULL;
}
if (Timer_Port) DeletePort(Timer_Port);
Timer_Port = NULL;
}
/***************** Opens a message port and the timer device **************/
int
OpenTimer(ULONG sec,ULONG micro) {
if ((Timer_Port = CreatePort(NULL,0)) == NULL)
return 0;
if (OpenDevice(TIMERNAME,UNIT_VBLANK,IOR &Time_Request,NULL) != NULL) {
DeletePort(Timer_Port);
Timer_Port = NULL;
return 0;
}
Time_Request.tr_node.io_Message.mn_ReplyPort = Timer_Port;
Time_Request.tr_node.io_Command = TR_ADDREQUEST;
Time_Request.tr_node.io_Flags = NULL;
Time_Request.tr_node.io_Error = NULL;
Time_Request.tr_time.tv_secs = sec;
Time_Request.tr_time.tv_micro = micro;
SendIO(IOR &Time_Request);
TimerMask = 1L<<Timer_Port->mp_SigBit;
return 1;
}
/************************** end of OpenTimer *******************************/
/***************** Sends another request to the timer if necessary ********/
void
ResetTimeReq (ULONG sec,ULONG micro)
{
if (GetMsg(Timer_Port)) {
Time_Request.tr_time.tv_secs = sec;
Time_Request.tr_time.tv_micro = micro;
SendIO(IOR &Time_Request);
}
}
/***************** Abort the current Timer request **************/
void
AbortTimer(void)
{
AbortIO(IOR &Time_Request);
}